<template>
  <div class="chart">
    <div ref="chart" style="width: 100%; height: 300px"></div>
  </div>
</template>

<script>
export default {
  name: "Chart",
  props: ['options'],
  watch: {
      options: {
          handler () {
              this.setChart();
          },
        //   immediate: true,
          deep: true
      }
    // options() {
    //   this.setChart();
    // },
  },
  mounted() {
    this.setChart();
  },
  methods: {
    setChart() {
      const chart = this.$echarts.init(this.$refs.chart);
      chart.setOption(this.options);
      window.addEventListener("resize", () => {
        chart.resize();
      });
    },
  },
};
</script>

<style lang='stylus' scoped>
.chart {
//   height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
